//
//  MyTakeOrderDetailAddressCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2021/1/27.
//  Copyright © 2021 吕晶. All rights reserved.
//

#import "MyTakeOrderDetailAddressCell.h"

@interface MyTakeOrderDetailAddressCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *faImgView;
@property (nonatomic, strong) UILabel *faAddressLab;
@property (nonatomic, strong) UILabel *faDetailLab;
@property (nonatomic, strong) UILabel *faInfoLab;
@property (nonatomic, strong) UILabel *marginLine;
@property (nonatomic, strong) UIImageView *shouImgView;
@property (nonatomic, strong) UILabel *shAddressLab;
@property (nonatomic, strong) UILabel *shDetailLab;
@property (nonatomic, strong) UILabel *shInfoLab;
@property (nonatomic, strong) UILabel *linkLine;

@end

@implementation MyTakeOrderDetailAddressCell

+ (instancetype)MyTakeOrderDetailAddressCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"MyTakeOrderDetailAddressCell";
    MyTakeOrderDetailAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[MyTakeOrderDetailAddressCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = Color_backgroundColor;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.faImgView = [UIImageView new];
        self.faImgView.image = [UIImage imageNamed:@"icon_add_fa"];
        [self.bgView addSubview:self.faImgView];
        
        self.faAddressLab = [UILabel new];
        self.faAddressLab.textColor = HexColor(0x2B2C44);
        self.faAddressLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.faAddressLab];
        
        self.faDetailLab = [UILabel new];
        self.faDetailLab.textColor = HexColor(0x2B2C44);
        self.faDetailLab.font = BoldFontOfSize(14);
        self.faDetailLab.numberOfLines = 0;
        [self.bgView addSubview:self.faDetailLab];
        
        self.faInfoLab = [UILabel new];
        self.faInfoLab.textColor = HexColor(0x585974);
        self.faInfoLab.font = BoldFontOfSize(12);
        self.faInfoLab.numberOfLines = 0;
        [self.bgView addSubview:self.faInfoLab];
        
        self.shouImgView = [UIImageView new];
        self.shouImgView.image = [UIImage imageNamed:@"icon_add_shou"];
        [self.bgView addSubview:self.shouImgView];
        
        self.shAddressLab = [UILabel new];
        self.shAddressLab.textColor = HexColor(0x2B2C44);
        self.shAddressLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.shAddressLab];
        
        self.shDetailLab = [UILabel new];
        self.shDetailLab.textColor = HexColor(0x2B2C44);
        self.shDetailLab.font = BoldFontOfSize(14);
        self.shDetailLab.numberOfLines = 0;
        [self.bgView addSubview:self.shDetailLab];
        
        self.shInfoLab = [UILabel new];
        self.shInfoLab.textColor = HexColor(0x585974);
        self.shInfoLab.font = BoldFontOfSize(12);
        self.shInfoLab.numberOfLines = 0;
        [self.bgView addSubview:self.shInfoLab];
        
        self.marginLine = [UILabel new];
        self.marginLine.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.marginLine];
        
        self.linkLine = [UILabel new];
        self.linkLine.backgroundColor = HexColorA(0x3D68EB, 0.2);
        [self.bgView addSubview:self.linkLine];
    }
    return self;
}

-(void)setModel:(MyTakeOrderDetailMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 0;
    self.bgView.nim_width = ScreenW - 2 * self.bgView.nim_left;
    
    self.faAddressLab.text = [NSString stringWithFormat:@"%@ %@ %@",self.model.s_province,self.model.s_city,self.model.s_town];
    [self.faAddressLab sizeToFit];
    self.faAddressLab.nim_left = 59;
    self.faAddressLab.nim_top = 15;
    self.faAddressLab.nim_width = self.bgView.nim_width - 70 - 10 - self.faAddressLab.nim_left;
    
    self.faDetailLab.nim_width = self.faAddressLab.nim_width;
    self.faDetailLab.text = self.model.s_address;
    self.faDetailLab.nim_left = self.faAddressLab.nim_left;
    self.faDetailLab.nim_top = self.faAddressLab.nim_bottom + 5;
    [self.faDetailLab sizeToFit];
    self.faDetailLab.nim_width = self.faAddressLab.nim_width;
    
    self.faInfoLab.nim_width = self.faDetailLab.nim_width;
    self.faInfoLab.text = [NSString stringWithFormat:@"%@ %@",self.model.s_tel_name,self.model.s_phone];
    self.faInfoLab.nim_left = self.faDetailLab.nim_left;
    self.faInfoLab.nim_top = self.faDetailLab.nim_bottom + 10;
    [self.faInfoLab sizeToFit];
    self.faInfoLab.nim_width = self.faDetailLab.nim_width;
    
    
    self.marginLine.nim_left = self.faAddressLab.nim_left - 5;
    self.marginLine.nim_top = self.faInfoLab.nim_bottom + 10;
    self.marginLine.nim_width = self.bgView.nim_width - self.marginLine.nim_left;
    self.marginLine.nim_height = 1;

    self.shAddressLab.text = [NSString stringWithFormat:@"%@ %@ %@",self.model.r_province,self.model.r_city,self.model.r_town];
    [self.shAddressLab sizeToFit];
    self.shAddressLab.nim_left = 59;
    self.shAddressLab.nim_top = 10 + self.marginLine.nim_bottom;
    self.shAddressLab.nim_width = self.bgView.nim_width - 70 - 10 - self.shAddressLab.nim_left;
    
    self.shDetailLab.nim_width = self.shAddressLab.nim_width;
    self.shDetailLab.text = self.model.r_address;
    self.shDetailLab.nim_left = self.shAddressLab.nim_left;
    self.shDetailLab.nim_top = self.shAddressLab.nim_bottom + 5;
    [self.shDetailLab sizeToFit];
    self.shDetailLab.nim_width = self.shAddressLab.nim_width;
    
    self.shInfoLab.nim_width = self.shDetailLab.nim_width;
    self.shInfoLab.text = [NSString stringWithFormat:@"%@ %@",self.model.r_tel_name,self.model.r_phone];
    self.shInfoLab.nim_left = self.shDetailLab.nim_left;
    self.shInfoLab.nim_top = self.shDetailLab.nim_bottom + 10;
    [self.shInfoLab sizeToFit];
    self.shInfoLab.nim_width = self.shDetailLab.nim_width;
    
    self.faImgView.nim_width = 22;
    self.faImgView.nim_height = 22;
    self.faImgView.nim_left = 20;
    self.faImgView.nim_top = (self.marginLine.nim_top - self.faImgView.nim_width) * 0.5;
    
    self.shouImgView.nim_width = 22;
    self.shouImgView.nim_height = 22;
    self.shouImgView.nim_left = 20;
    self.shouImgView.nim_top = self.shInfoLab.nim_bottom + 15 - (self.shInfoLab.nim_bottom + 15 - self.marginLine.nim_bottom - self.shouImgView.nim_height) * 0.5 - self.shouImgView.nim_height;
    
    self.linkLine.nim_width = 2;
    self.linkLine.nim_top = self.faImgView.nim_bottom + 3;
    self.linkLine.nim_height = self.shouImgView.nim_top - 3 - self.linkLine.nim_top;
    self.linkLine.nim_centerX = self.faImgView.nim_centerX;
    
    self.bgView.nim_height = self.shInfoLab.nim_bottom + 15;
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
